<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.9.1"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Arduino AudioKit HAL: Arduino ADF/AudioKit HAL</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">Arduino AudioKit HAL
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.9.1 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search','.html');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
</div><!-- top -->
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="PageDoc"><div class="header">
  <div class="headertitle">
<div class="title">Arduino ADF/AudioKit HAL </div>  </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p><a class="anchor" id="md_README"></a> There are different ESP32 Audio boards available that can be programmed with the Espressif ADF Framework.</p>
<p><img src="https://pschatzmann.github.io/Resources/img/audio-toolkit.png" alt="Audio Kit" class="inline"/></p>
<p>The ADF Framework contains an abstraction layer to support different CODEC chips. Unfortunately ADF can not be used in Arduino, but it would be quite useful to have this functionality also available.</p>
<p>Because I wanted to have a proper support of the AudioKit for my <a href="https://github.com/pschatzmann/arduino-audio-tools">Arduino Audio Tools</a> library and since my Audio Tools are header only, I decided to provide this functionality in a separate project.</p>
<p>I converted the <b>audio_boards</b> and their related <b>drivers</b> into an <b>Arduino Library</b> and provide an easy to use C++ class which configures both the CODEC and I2S. I also tried to abstract away all ESP32 specific funcationality.</p>
<p>So with this project it should now get quite easy to use these boards also in Arduino.</p>
<h1><a class="anchor" id="autotoc_md1"></a>
Configuration</h1>
<p>You must define your board and the default settings in the <code><a class="el" href="_audio_kit_settings_8h.html" title="AUDIOKIT_BOARD selects a specic board: 1) lyrat_v4_3 2) lyrat_v4_2 3) lyrat_mini_v1_1 4) esp32_s2_kal...">libraries/arduino-audiokit/src/AudioKitSettings.h</a></code> file. Please note that the functionlity will <b>not work</b> properly if this is done in the Sketch.</p>
<div class="fragment"><div class="line"> * @brief AUDIOKIT_BOARD selects a specic board:</div>
<div class="line"> * 1) lyrat_v4_3</div>
<div class="line"> * 2) lyrat_v4_2 - DRAFT Not Tested</div>
<div class="line"> * 3) lyrat_mini_v1_1 - DRAFT Not Tested</div>
<div class="line"> * 4) esp32_s2_kaluga_1_v1_2 - DRAFT Not Tested</div>
<div class="line"> * 5) ai_thinker (ES8388) 2957 3478 A149 2762</div>
<div class="line"> * 6) ai_thinker (AC101) 2762 2957</div>
<div class="line"> * 7) ai_thinker (ES8388) 2957</div>
<div class="line"> * 10) generic_es8388</div>
<div class="line"> * 11) generic_es8311</div>
<div class="line"> */</div>
<div class="line"> </div>
<div class="line">#define AUDIOKIT_BOARD 1</div>
</div><!-- fragment --><p> Here the lyrat v4.3 has been selected.</p>
<p>Unfortunately AI Thinker created a big mess with their boards using different Audio chips and pin assingments, all of them using the same version number. You might need to make an educated guess by looking at the number after the version and if you have a 2957 board, you need to check all 3 options!</p>
<h1><a class="anchor" id="autotoc_md2"></a>
Example Sketch</h1>
<p>Here is an example sketch that writes audio data to the audio kit board via I2S. By default I2S is set up as master and the codec as slave, the sample size is 16 bits and the sample rate is 44.1k/sec - if you did not change the default settings.</p>
<p>You can adjust these parameters by setting your requested values in the cfg below:</p>
<div class="fragment"><div class="line"> {C++}</div>
<div class="line">#include &quot;AudioKit.h&quot;</div>
<div class="line">#include &quot;SineWaveGenerator.h&quot;</div>
<div class="line"> </div>
<div class="line">AudioKit kit;</div>
<div class="line">SineWaveGenerator wave;</div>
<div class="line">const int BUFFER_SIZE = 1024;</div>
<div class="line">uint8_t buffer[BUFFER_SIZE];</div>
<div class="line"> </div>
<div class="line">void setup() {</div>
<div class="line">  // open in write mode</div>
<div class="line">  auto cfg = kit.defaultConfig(true);</div>
<div class="line">  cfg.sample_rate = AUDIO_HAL_22K_SAMPLES;</div>
<div class="line">  kit.begin(cfg);</div>
<div class="line"> </div>
<div class="line">  // 1000 hz</div>
<div class="line">  wave.setFrequency(1000);</div>
<div class="line">  wave.setSampleRate(cfg.sampleRate());</div>
<div class="line">}</div>
<div class="line"> </div>
<div class="line">void loop() {</div>
<div class="line">  size_t l = wave.read(buffer, BUFFER_SIZE);</div>
<div class="line">  kit.write(buffer, l);</div>
<div class="line">}</div>
</div><!-- fragment --><p>However <b>I recommend</b> to use my <a href="https://github.com/pschatzmann/arduino-audio-tools">Arduino Audio Tools Library</a> which implements an easy to use Stream API with additional functionality on top of this and it has plenty of <a href="https://github.com/pschatzmann/arduino-audio-tools/tree/main/examples/examples-audiokit">examples</a>.</p>
<p>You can also use this functionality just to set up the codec chip w/o doing any input or output. In this case you can set cfg.is_i2s_active = false;</p>
<h1><a class="anchor" id="autotoc_md3"></a>
Logging</h1>
<p>The functionality has a built in logger. The default log level has been set to Warning. You can change it like this:</p>
<div class="fragment"><div class="line">{C++}</div>
<div class="line"> LOGLEVEL_AUDIOKIT = AudioKitDebug; // or AudiKitInfo, AudioKitWarning, AudioKitError</div>
</div><!-- fragment --><h1><a class="anchor" id="autotoc_md4"></a>
Documentation</h1>
<p>Here is the documentaion of the <a href="https://pschatzmann.github.io/arduino-audiokit/html/classaudiokit_1_1_audio_kit.html">AudioKit class</a>.</p>
<p>Further information can be found in the <a href="https://github.com/pschatzmann/arduino-audiokit/wiki">Wiki</a> and my <a href="https://www.pschatzmann.ch/home/tag/esp32audiokit/">Blogs</a>.</p>
<h1><a class="anchor" id="autotoc_md5"></a>
Installation in Arduino</h1>
<p>You can download the library as zip and call include Library -&gt; zip library. Or you can git clone this project into the Arduino libraries folder e.g. with</p>
<div class="fragment"><div class="line">cd  ~/Documents/Arduino/libraries</div>
<div class="line">git clone https://github.com/pschatzmann/arduino-audiokit.git</div>
</div><!-- fragment --><p>If you want to use the library in PlatformIO, you can find a <a href="https://github.com/pschatzmann/arduino-audiokit-hal/wiki/PlatformIO">detailed description in the Wiki</a>.</p>
<h1><a class="anchor" id="autotoc_md6"></a>
Supported Devices / Processors</h1>
<p>The examples have been tested with a <b>AI Thinker v2.2</b>: both versions - the one with the ES8388 and the other with the AC101. I also tested with a <b>LyraT</b>. I do not own any other AudioKit devices, so I can't guarantee that they work properly. I also made sure that the code is compiling on other processors, but I did not perform any tests. Please note that in this case because I2S is not standardized in Arduino, you need to take care of the I2S initialization and processing yourself on non ESP32 boards. </p>
</div></div><!-- PageDoc -->
</div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by&#160;<a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.1
</small></address>
</body>
</html>
